import config from "@/config"
/**
 * 主题样式
 * @author liu_jshan
 * @date 2024-02-25
 * @version 1.0
 */

const themes = config.themes

//初始化主题样式
function init() {
    const theme = localStorage.getItem('theme')
    if (theme) window.document.body.className = theme
    else { //默认加载常规主题样式
        change('normal')
    }
}

function change(theme) {
    if (!theme || themes.indexOf(theme) === -1) return
    window.document.body.className = theme
    localStorage.setItem('theme', theme)
}

function sequentialSwitch() {
    const theme = localStorage.getItem('theme')
    let index = themes.indexOf(theme)
    if (index + 1 > themes.length - 1) {
        index = 0;
    } else index += 1;
    change(themes[index])
}

const themeStyles = {
    init,
    change,
    sequentialSwitch
}

export default themeStyles